﻿using System.Collections.Generic;

namespace Cms.Domain
{
    public abstract class Template : ContentSetContainer
    {
        private IList<Page> _pages;
        private SourceCode _sourceCode;

        protected Template()
        {
            _pages = new List<Page>();
        }

        public virtual SourceCode SourceCode
        {
            get { return _sourceCode; }
            set { _sourceCode = value; }
        }
        
        public virtual IList<Page> Pages
        {
            get { return _pages; }
            set { _pages = value; }
        }
        
        public virtual string GetCode()
        {
            return _sourceCode != null ? _sourceCode.CurrentVersion.Code : string.Empty;
        }
        
        public virtual void SetCode(string code, Administrator editedBy)
        {
            if (_sourceCode == null)
            {
                _sourceCode = new SourceCode();
                _sourceCode.Site = Site;
            }
            _sourceCode.AddVersion(code, editedBy);
        }
    }
}